
// number string boolean
function add(n1: number, n2: number, showResult: boolean, resultPhrase: string) {
    const result = n1 + n1;

    if (showResult) {
        console.log(resultPhrase + result);
    } else {
        return n1 + n2;
    }
}

let number1: number = 5,
    number2: number = 10,
    printResult: boolean = true,
    resultPhrase: string = 'result：';

add(number1, number2, printResult, resultPhrase);

// object array 元组
const person: {
    name: string,
    age: number,
    hobbies: string[],
    role: [number, string]
} = {
    name: '张三',
    age: 24,
    hobbies: ['Sports', 'Cooking'],
    role: [2, 'admin']
}

// person.hobbies.push(1) 类型不同 error ！！！

// person.name = 1 // ！！！

for(const hobby of person.hobbies) {
    console.log(hobby)
    // console.log(hobby.map) // 提示很好 只提示该类型可用的方法
}

// person.role[0] = '1' 元组固定了数组第一项的类型为number
// person.role.push(2) // push新增无法检测
// person.role = [1, 'admin', 'name'] // 直接赋值是可以检测的

console.log(person)

// enum
enum Role { admin = 1 }

let role = Role.admin

if(role === 1) {
    console.log(true)
}

// any 任意类型
let names: any[] = [1, {}, '']

console.log(names)